package nz.ac.massey.cs.se400_2013.ass3;

import java.util.Collection;
import java.util.HashSet;

public class Paper implements Visitable{
	private String id = null;
	private String name = null;
	private Collection<Student> enrolledStudents = new HashSet<Student>();
	private Collection<Course> courses = new HashSet<Course>();
	
	@Override
	public void accepts(Visitor visitor) {
		for (Student s:enrolledStudents) {
			s.accepts(visitor);
		}
		visitor.visit(this);
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public void addCourse(Course course){
		if(this.courses.add(course)){
			course.addPaper(this);
		}
	}
	
	public void removeCourse(Course course){
		if(this.courses.remove(course)){
			course.removePaper(this);
		}
	}
	
	public void addStudent(Student student){
		if(this.enrolledStudents.add(student)){
			student.addPaper(this);
		}
	}
	
	public void removeStudent(Student student){
		if(this.enrolledStudents.remove(student)){
			student.removePaper(this);
		}
	}
	
	public Collection<Student> getEnrolledStudents() {
		return enrolledStudents;
	}
	public void setEnrolledStudents(Collection<Student> enrolledStudents) {
		this.enrolledStudents = enrolledStudents;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Paper other = (Paper) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "Paper [id=" + id + ", name=" + name + "]";
	}
}
